#include "stdafx.h"
#include "selfcontrol.h"

const float SelfControl::MAX_BOOST_DELTA = 0.2;
const float SelfControl::MAX_ROT_DELTA = 0.08;

SelfControl::SelfControl(const Mage * mage,
                         const UnitsArray *units,
                         const SpellsArray *spells,
                         const BonusesArray *bonuses) :
    _mage(mage),
    _visibleUnits(units),
    _visibleSpells(spells),
    _visibleBonuses(bonuses),
    _action(ISelfControl::Action_None),
    _boostDelta(0.0f),
    _rotDelta(0.0f)
{
}

SelfControl::~SelfControl()
{
}

const IUnitsArray *SelfControl::getVisibleUnits() const
{
    return _visibleUnits;
}

const ISpellsArray *SelfControl::getVisibleSpells() const
{
    return _visibleSpells;
}

const IBonusesArray *SelfControl::getVisibleBonuses() const
{
    return _visibleBonuses;
}

void SelfControl::boost(float delta)
{
    _boostDelta = qMax(-MAX_BOOST_DELTA, qMin(MAX_BOOST_DELTA, delta));
}

float SelfControl::getMaxBoostDelta() const
{
    return MAX_BOOST_DELTA;
}

void SelfControl::rotate(float delta)
{
    _rotDelta = qMax(-MAX_ROT_DELTA, qMin(MAX_ROT_DELTA, delta));
}

float SelfControl::getMaxRotationDelta() const
{
    return MAX_ROT_DELTA;
}

void SelfControl::act(Action action)
{
    unsigned value = action;
    if (value >= ActionsNum) {
        value = Action_None;
    }
    _action = static_cast<Action>(value);
}

int SelfControl::health() const
{
    return _mage->health();
}

int SelfControl::mana() const
{
    return _mage->mana();
}

const IEffectsArray * SelfControl::effects() const
{
    return _mage->effects();
}

float SelfControl::speed() const
{
    return _mage->speed();
}

float SelfControl::direction() const
{
    return _mage->direction();
}

float SelfControl::speedX() const
{
    return _mage->speedX();
}

float SelfControl::speedY() const
{
    return _mage->speedY();
}

float SelfControl::x() const
{
    return _mage->x();
}

float SelfControl::y() const
{
    return _mage->y();
}

float SelfControl::getBoostDelta() const
{
    return _boostDelta;
}

float SelfControl::getRotationDelta() const
{
    return _rotDelta;
}

SelfControl::Action SelfControl::action() const
{
    return _action;
}
